<?php

/**
 * MVM_MALL 网上商店系统  商品类型管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-06 $
 * $Id: goods_type.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if ($action=='list') {
    require_once MVMMALL_ROOT.'./include/pager.class.php';
    $total_count = $db->counter("{$tablepre}att_type");
    $page        = $page ? (int)$page:1;
    $list_num    = 10;
    $rowset      = new Pager($total_count,$list_num,$page);
    $from_record = $rowset->_offset();
    $type_rt     = array();
    $result      = $db->query("SELECT * FROM `{$tablepre}att_type` LIMIT $from_record, $list_num");
    while ($rt   = $db->fetch_array($result)){
        $rt['edit']      = "admincp.php?module=$module&action=edit&uid=$rt[uid]";
        $rt['del']       = "admincp.php?module=$module&action=del&uid=$rt[uid]&per=ajax";
        $rt['att_list']  = "admincp.php?module=attribute&action=list&type_id=$rt[uid]";
        $rt['enabled']   = $rt['enabled']==1 ? $lang['yes'] : $lang['no'] ;
        $type_rt[]       = $rt;
    }
    $page_list = $rowset->link("admincp.php?module=$module&action=$action&page=");
    require_once template('goods_type');
    footer();
} elseif ($action=='add') {
    if($setp==1 && $_POST){
        $name    = dhtmlchars($name);
        $enabled = (int)$enabled;
        $nums    = $db->counter("{$tablepre}att_type","where name='$name'");
        $nums>0 &&  admin_msg('already_exist');
        $db->query("INSERT INTO `{$tablepre}att_type` SET name = '$name',enabled = '$enabled'");
        admin_msg('success','admincp.php?module=goods_type&action=list');
    } else {
        $open_chk = 'checked';
        require_once template('goods_type_add');
        footer();
    }
} elseif ($action=='edit' && is_numeric($uid)) {
    if($setp==1 && $_POST){
        $name    = dhtmlchars($name);
        $enabled = (int)$enabled;
        $nums    = $db->counter("{$tablepre}att_type","where name='$name' and uid<>'$uid'");
        $nums>0 &&  admin_msg('already_exist');
        $db->query("UPDATE `{$tablepre}att_type` SET name = '$name',enabled = '$enabled' WHERE  uid='$uid'");
        admin_msg('success','admincp.php?module=goods_type&action=list');
    } else {
        $goods_type = $db->get_one("SELECT * FROM {$tablepre}att_type WHERE uid = '$uid'");
        @extract($goods_type,EXTR_OVERWRITE);
        $enabled==1 ? $open_chk = 'checked' : $disabled_chk = 'checked';
        require_once template('goods_type_add');
        footer();
    }
} elseif ($action=='del' && is_numeric($uid)) {
    $db->query("DELETE FROM `{$tablepre}att_type` WHERE uid = '$uid'");
    $db->query("DELETE FROM `{$tablepre}attribute` WHERE type_id = '$uid'");
    $per!='ajax' && admin_msg('success',dreferer());
} else {
    admin_msg('pass_worng');
}